package com.java2104.service;

import com.java2104.entity.Notice;
import com.java2104.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;

    public List<Notice> getNotices(String title,String content){
        if(title!=null){
            title = title.trim();//把字符串中多余的空格去掉
        }
        if(content!=null){
            content = content.trim();//把字符串中多余的空格去掉
        }
        return noticeMapper.findNotices(title,content);
    }

    public Map save(Notice notice){
        Map ret = new HashMap();
        noticeMapper.insert(notice);//保存用户信息
        if(true){
            ret.put("status","success");
            ret.put("msg","添加成功");
        }else {
            ret.put("status","fail");
            ret.put("msg","该登录名重复，请更换其他登录名！");
        }
        return ret;
    }

    public void update(Notice notice){
        noticeMapper.updateByPrimaryKey(notice);
    }
    public Notice get(Integer id){
        return noticeMapper.findByPrimaryKey(id);
    }

    public int delete(List<Integer> ids){
        return noticeMapper.batchDelete(ids);
    }
}
